home *** CD-ROM | disk | FTP | other *** search
/ Monster Media 1994 #2 / Monster Media No. 2 (Monster Media)(1994).ISO / prog_gen / xv_pc16a.zip / DIR.PAS < prev    next >
Pascal/Delphi Source File  |  1994-04-20  |  2KB  |  116 lines

  1. PROGRAM Dir;
  2. {
  3. XView-PC demonstration:
  4. A window with a directory display for file selection.
  5. By Antonio Carlos Moreirao de Queiroz - acmq@coe.ufrj.br
  6. Note that no memory is used for the directory.
  7. }
  8.  
  9. USES Dos,Graph,XView;
  10.  
  11. VAR
  12.   names,total,k:INTEGER;
  13.  
  14. VAR
  15.   fmsg,ttymsg:Xv_opaque;
  16.   fdirectory,cdirectory,tmask,tfile:Xv_opaque;
  17.  
  18. {$F+}
  19.  
  20. PROCEDURE ReadDirectory(obj:Xv_opaque);
  21. VAR
  22.   srec:SearchRec;
  23.  
  24. BEGIN
  25.   SetTextStyle(smallfont,horizdir,4);
  26.   IF obj<>cdirectory THEN BEGIN
  27.     SetFillStyle(SolidFill,cdirectory^.back_color);
  28.     Bar(0,0,cdirectory^.dx,cdirectory^.dy)
  29.   END;
  30.   names:=(cdirectory^.dx) div 78;
  31.   k:=0;
  32.   FindFirst(tmask^.panel_value,AnyFile,srec);
  33.   WHILE DosError=0 DO BEGIN
  34.     OutTextXY(3+(k mod names)*78,(k div names)*8,srec.Name);
  35.     FindNext(srec);
  36.     Inc(k)
  37.   END;
  38.   total:=k-1
  39. END;
  40.  
  41. PROCEDURE SelectFile(obj:Xv_opaque);
  42. VAR
  43.   srec:SearchRec;
  44.   i:INTEGER;
  45.   D:DirStr;
  46.   N:NameStr;
  47.   E:ExtStr;
  48.  
  49. BEGIN
  50.   IF ie_code=MS_LEFT THEN BEGIN
  51.     k:=(ie_locx-3) div 78;
  52.     IF k<names THEN BEGIN
  53.       k:=k+((ie_locy-3) div 8)*names;
  54.       IF k<=total THEN BEGIN
  55.         i:=0;
  56.         FindFirst(tmask^.panel_value,AnyFile,srec);
  57.         WHILE (DosError=0) and (i<k) DO BEGIN
  58.           FindNext(srec);
  59.           Inc(i)
  60.         END;
  61.         FSplit(tmask^.panel_value,D,N,E);
  62.         tfile^.panel_value:=FExpand(D+srec.Name);
  63.         xv_set(tfile,tfile^.xv_label)
  64.       END
  65.     END
  66.   END
  67. END;
  68.  
  69. PROCEDURE OpenFile(obj:Xv_opaque);
  70. BEGIN
  71.   ttysw_output(ttymsg,'Selected file: '+tfile^.panel_value+^M^J);
  72. END;
  73.  
  74. {$F-}
  75.  
  76. BEGIN
  77.   xv_init(0,0);
  78.   fmsg:=xv_create(frame);
  79.   WITH fmsg^ DO BEGIN
  80.     xv_label:='Messages';
  81.     y:=160;
  82.     dx:=319;
  83.     dy:=159;
  84.   END;
  85.   ttymsg:=xv_create(tty);
  86.   WITH ttymsg^ DO BEGIN
  87.   END;
  88.   fdirectory:=xv_create(frame);
  89.   WITH fdirectory^ DO BEGIN
  90.     xv_label:='File selection';
  91.     dx:=319;
  92.     dy:=159;
  93.   END;
  94.   cdirectory:=xv_create(canvas);
  95.   WITH cdirectory^ DO BEGIN
  96.     y:=30;
  97.     notify_handler:=ReadDirectory;
  98.     event_handler:=SelectFile;
  99.   END;
  100.   tmask:=xv_create(textfield);
  101.   WITH tmask^ DO BEGIN
  102.     xv_label:='Mask';
  103.     y:=15;
  104.     value_length:=33;
  105.     panel_value:='*.*';
  106.     notify_handler:=ReadDirectory;
  107.   END;
  108.   tfile:=xv_create(textfield);
  109.   WITH tfile^ DO BEGIN
  110.     xv_label:='File';
  111.     value_length:=33;
  112.     notify_handler:=OpenFile;
  113.   END;
  114.   xv_main_loop(fdirectory);
  115. END.
  116.